package com.feicheng.lanniao.controller;

import com.feicheng.lanniao.entity.CarImage;
import com.feicheng.lanniao.entity.HouseImage;
import com.feicheng.lanniao.result.ResultInfo;
import com.feicheng.lanniao.service.HouseImageService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author tianchunlei
 * @Des //房屋小图接口类
 * @Date 2021/9/27
 **/
@RestController
@RequestMapping("/lanniao-admin/house")
public class HouseImageController {

    @Resource
    private HouseImageService houseImageService;

    /**
     * @Author tianchunlei
     * @Description 批量上传小图接口
     * @Date 2021/9/26 15:33
     * @Param images 多张图片拼接的地址 images，关联的房屋idid
     * @return
     */
    @PutMapping("/image/upload")
    public ResultInfo carImageUpload(Integer houseId, String images){
        //解析多张图片的字符串
        String[] imageUrls = images.split(",");
        List<HouseImage> houseImageUrlList = new ArrayList<>();
        for (String houseImageUrl : imageUrls) {
            HouseImage houseImage = new HouseImage(houseId,houseImageUrl);
            houseImageUrlList.add(houseImage);
        }
        return houseImageService.batchAdd(houseImageUrlList);
    }

    /**
     * @Author tianchunlei
     * @Description //批量删除小图片地址的接口
     * @Date 2021/9/26 16:48
     * @Param houseId
     * @return
     */
    @DeleteMapping("/image/remove/{houseId}")
    public ResultInfo deleteImageUrl(@PathVariable("houseId") Integer houseId){
        return houseImageService.batchDelete(houseId);
    }

    /**
     * @Author tianchunlei
     * @Description //按照房屋编号查询车辆小图集合
     * @Date 2021/9/26 16:57
     * @Param houseId
     * @return
     */
    @GetMapping("/image/list/{houseId}")
    public ResultInfo list(@PathVariable("houseId") Integer houseId){
        return houseImageService.selectUrlAll(houseId);
    }
}
